﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace timetableasy.Models
{
    public class CampusRepository
    {
        private TimeTableDBDataContext db = new TimeTableDBDataContext();

        //Query Methods
        public IQueryable<Campus> FindAllCampuses()
        {
            return db.Campuses;
        }

        public List<Campus> GetAllCampuses()
        {
            return db.Campuses.ToList<Campus>();
        }

        public List<String> GetAllCampusesNames()
        {
            List<string> list = new List<string>();
            foreach (Campus c in this.GetAllCampuses())
            {
                list.Add(c.CampusName);
            }
            return list;
        }

        public Campus GetCampusById(int id)
        {
            return db.Campuses.SingleOrDefault(c => c.CampusId == id);
        }

        public int GetCampusIdByName(string name)
        {
            return db.Campuses.SingleOrDefault(c => c.CampusName == name).CampusId;
        }

        //Insert/Delete Methods

        public void Add(Campus campus)
        {
            db.Campuses.InsertOnSubmit(campus);
        }

        public void Delete(Campus campus)
        {
            db.Campuses.DeleteOnSubmit(campus);
        }

        //Persistence

        public void Save()
        {
            db.SubmitChanges();
        }
    }
}